package io.github.talelin.latticy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.github.talelin.latticy.model.AswDO;
import io.github.talelin.latticy.model.AswItemDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author generator@TaleLin
 * @since 2021-05-28
 */
@Repository
public interface AswMapper extends BaseMapper<AswDO> {


    @Select("SELECT id,chckType,aswTitle,aswType,trueAsw,analysisTxt,answerCenter,sort_id,create_time,update_time,delete_time FROM asw WHERE delete_time IS NULL")
    List<Map<String,Object>> fingAllAsw();

    @Select("select * from asw_item where delete_time IS NULL and aswItem_id = #{aswItemID}")
    List<AswItemDO> fingAllAswItemByID(Integer aswItemID);

    @Select("SELECT id,chckType,aswtitle,aswtype,trueAsw,analysisTxt,answerCenter,sort_id,create_time,update_time,delete_time FROM asw WHERE sort_id = #{ID} and delete_time IS NULL")
    List<Map<String,Object>> findAswByID(Integer ID);

    @Select("select MAX(id) from asw")
    Integer findMaxId();

    @Insert("INSERT INTO `asw_item` (`name`, `value`, `text`, `aswItem_id`) VALUES (#{name}, #{value}, #{text}, #{aswItemID})")
    Integer insertAswItem(Map<String,Object> map);

    @Select("select asw_type_name from asw_type where id =#{sortID} ")
    String selectNameBySortID(Integer sortID);

    @Select("update asw_item SET delete_time = now()  where aswItem_id =#{id} ")
    Integer deleteAswItemByID(Integer id);
}
